package com.CST.controller;


import com.CST.annotation.*;
import com.CST.common.api.Response;
import com.CST.common.api.ResultObject;
import com.CST.common.constant.*;
import com.CST.dto.DateDTO;
import com.CST.entity.*;
import com.CST.request.RdCostsalaryrelationrequest;
import com.CST.service.*;
import com.CST.util.PageHelperTool;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import io.swagger.annotations.*;
import java.util.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
* @author ly
* @since 2021-12-08
*/
@Api(tags = {"成本薪酬系统对应"})
@RestController
@RequestMapping("/rdCostsalaryrelation")

    public class RdCostsalaryrelationController {

    @Autowired
    private IRdCostsalaryrelationService targetService;


    @PostMapping("/getRdCostSalaryRelation")
    @ApiOperation("获取成本薪酬系统对应")
    public ResultObject getRdCostSalaryRelation(@RequestBody RdCostsalaryrelation entity) {
        List<RdCostsalaryrelation> result = targetService.getRdCostSalaryRelation(entity);
        if (CollectionUtils.isEmpty(result)) {
            return ResultObject.successReturn(new ArrayList<RdCostsalaryrelation>());
        }
        return ResultObject.successReturn(PageHelperTool.excutePageInfo(result, entity.getPageIndex(), entity.getPageSize()));
    }

    @PostMapping("/download")
    public void downloadExcel(HttpServletResponse response,@RequestBody RdCostsalaryrelation entity) {
        targetService.downloadExcel(response,entity);
    }


    @PostMapping("/insertBatchRdCostSalaryRelation")
    @ApiOperation("批量添加")
    public ResultObject insertBatchRdCostSalaryRelation(@RequestBody List<RdCostsalaryrelation> list) {

        Response result = targetService.insertBatchRdCostSalaryRelation(list);
        return ResultObject.resultReturn(result);
    }

    @PostMapping("/modifyRdCostSalaryRelation")
    @ApiOperation("修改成本薪酬系统对应")
    public ResultObject modifyRdCostSalaryRelation(@RequestBody RdCostsalaryrelation entity) {
        if (entity.getId() == null || entity.getId() == 0) {
            return ResultObject.errorReturn("未获取到记录ID!");
        }
        Response result = targetService.modifyRdCostSalaryRelation(entity);
        return ResultObject.resultReturn(result);
    }

    @PostMapping("/batchDeleteRdCostSalaryRelation")
    @ApiOperation("删除成本薪酬系统对应")
    public ResultObject batchDeleteRdCostSalaryRelation(@RequestBody List<Integer> ids) {
        if (ids == null || ids.stream().count() == 0) {
            return ResultObject.errorReturn("请选择要删除的记录");
        }
        Response result = targetService.batchDeleteRdCostSalaryRelation(ids);
        return ResultObject.resultReturn(result);
    }

    /**
     * 按年月获取费用要素（成本项目编码）
     */
    @PostMapping("/listCostItemByDate")
    @ApiOperation("按年月获取费用要素（成本项目编码）")
    public ResultObject listCostItemByDate(@RequestBody DateDTO dateDTO){
        List<RdCostsalaryrelation> list = targetService.listCostItemByDate(dateDTO);
        return ResultObject.successReturn(list);
    }

    /**
     * 检查未关联的账套项目
     */
    @PostMapping("/checkRelation")
    @ApiOperation("检查未关联的账套项目")
    public ResultObject checkRelation(@RequestBody DateDTO dateDTO){
        List<RdCostsalaryrelation> list = targetService.checkRelation(dateDTO);
        return ResultObject.successReturn(list);
    }

}

